package com.dai.zhenfujin.issue;

import android.content.Intent;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dai.zhenfujin.BaseAdapter.BaseViewHolder;
import com.dai.zhenfujin.Constants.Constants;
import com.dai.zhenfujin.R;
import com.dai.zhenfujin.adapter.IssueTypeAdpter;
import com.dai.zhenfujin.adapter.IssueTypeAdpter2;
import com.dai.zhenfujin.base.BaseFragment;
import com.dai.zhenfujin.bean.TypeListBean;
import com.dai.zhenfujin.http.CallBack;
import com.dai.zhenfujin.http.HttpClient;
import com.dai.zhenfujin.issue.activity.AlumIssueActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 发布
 */
public class IssueFragment extends BaseFragment implements View.OnClickListener{
    private View view;
    private ImageView imageView,ivReturn;
    private TextView tvTitleName;
    private TextView tvRoom,tvVehicle,tvMarriage,tvOther;//tvFans;
    private RecyclerView rvLeft,rvRight;
    private List<TypeListBean.TypelistBean> typeList = new ArrayList<>();
    private List<TypeListBean.TypelistBean> typeList2 = new ArrayList<>();
    private IssueTypeAdpter issueTypeAdpter;
    private IssueTypeAdpter2 issueTypeAdpter2;

    @Override
    public View initView() {
        view = View.inflate(mContext, R.layout.fragment_issue2,null);
        rvLeft = view.findViewById(R.id.rv_left);
        rvRight = view.findViewById(R.id.rv_right);
        imageView = view.findViewById(R.id.title_imageview);
        tvTitleName = view.findViewById(R.id.title_textview);
       /* imageView = view.findViewById(R.id.title_imageview);
        ivReturn = view.findViewById(R.id.title_return);
        tvTitleName = view.findViewById(R.id.title_textview);
        tvRoom = view.findViewById(R.id.issue_room);
        tvVehicle = view.findViewById(R.id.issue_vehicle);
        tvMarriage = view.findViewById(R.id.issue_marriage);
        tvOther = view.findViewById(R.id.issue_other);*/
       // tvFans = view.findViewById(R.id.issue_fans);
        return view;
    }

    @Override
    public void initData() {
        super.initData();
        tvTitleName.setText("发布");
        imageView.setVisibility(View.GONE);
        rvLeft.setLayoutManager(new LinearLayoutManager(mContext));
        //设置Item增加、移除动画
        rvLeft.setItemAnimator(new DefaultItemAnimator());
        issueTypeAdpter = new IssueTypeAdpter(mContext, typeList,new TypeItemListener());
        rvLeft.setAdapter(issueTypeAdpter);

        rvRight.setLayoutManager(new LinearLayoutManager(mContext));
        //设置Item增加、移除动画
        rvRight.setItemAnimator(new DefaultItemAnimator());
        issueTypeAdpter2 = new IssueTypeAdpter2(mContext, typeList2,new TypeItemListener2());
        rvRight.setAdapter(issueTypeAdpter2);
        getIssueType();
    }

    private void getIssueType() {
        Map<String, Object> params = new HashMap<>();
        Map<String, String> params2 = new HashMap<>();
        params2.put("type_id", 0 + "");
        params.put("req_bd",  params2);
        HttpClient.post(mContext, Constants.TYPELIST, params, new CallBack<TypeListBean>() {
            @Override
            public void onSuccess(TypeListBean resultBean) {
                typeList.clear();
                typeList.addAll(resultBean.getTypeList());
                issueTypeAdpter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
          /*  case R.id.issue_room://房
                Intent room = new Intent(mContext,AddRoomActivity.class);
                startActivity(room);
                break;
            case R.id.issue_vehicle://车
                Intent vehicle = new Intent(mContext,AddVehicleActivity.class);
                startActivity(vehicle);
                break;
            case R.id.issue_marriage://婚
                Intent marriage = new Intent(mContext,AddMarriageActivity.class);
                startActivity(marriage);
                break;
            case R.id.issue_other://其他
//                Intent other = new Intent(mContext,AddOtherActivity.class);
//                startActivity(other);
                break;*/
//            case R.id.issue_fans://粉丝福利
//                Intent fans = new Intent(mContext,AddFansActivity.class);
//                startActivity(fans);
//                break;
        }
    }

    class TypeItemListener implements BaseViewHolder.onItemCommonClickListener {
        @Override
        public void onItemClickListener(int position) {
            String id = typeList.get(position).getT_id();
            Map<String, Object> params = new HashMap<>();
            Map<String, String> params2 = new HashMap<>();
            params2.put("type_id", id);
            params.put("req_bd",  params2);
            HttpClient.post(mContext, Constants.TYPELIST, params, new CallBack<TypeListBean>() {
                @Override
                public void onSuccess(TypeListBean resultBean) {
                    typeList2.clear();
                    typeList2.addAll(resultBean.getTypeList());
                    issueTypeAdpter2.notifyDataSetChanged();
                }
            });
        }

        @Override
        public void onItemLongClickListener(int position) {

        }
    }

    class TypeItemListener2 implements BaseViewHolder.onItemCommonClickListener {
        @Override
        public void onItemClickListener(int position) {
            Intent intent = new Intent();
            intent.putExtra("name", typeList2.get(position).getT_name());
            intent.putExtra("id", typeList2.get(position).getT_id());
            intent.setClass(mContext,AlumIssueActivity.class);
            mContext.startActivity(intent);
        }

        @Override
        public void onItemLongClickListener(int position) {

        }
    }
}
